package com.mashibing.juc.c_009;

/**
 * 一个同步方法，调用另外一个同步方法，同一个线程得到的是同一把锁
 * @author: Yuanzt
 * @Date: 2021/3/24
 */
public class T {

    public synchronized void m1(){
        System.out.println(Thread.currentThread().getName() + " m1 start...");
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        m2();
        System.out.println(Thread.currentThread().getName() + " m1 end.");
    }

    public synchronized void m2(){
        System.out.println(Thread.currentThread().getName() + " m2 ");
    }

    public static void main(String[] args) {
//        new Thread(()->{
//            new T().m1();
//        },"Thread").start();
        new T().m1();
    }
}
